package com.yx.controller;

import com.yx.service.DisruptorMqService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author God.Jhon.Black
 * @date 2023-01-03
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private DisruptorMqService disruptorMqService;

    private ThreadPoolExecutor executor = new ThreadPoolExecutor(15, 20,
            100, TimeUnit.MICROSECONDS,
            new LinkedBlockingDeque<>());

    @RequestMapping()
    public void send() {
        for (int i = 0; i < 100000; i++) {
            final int flag = i;
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    disruptorMqService.sayHelloMq("发送消息:" + flag);
                }
            });
        }
    }
}
